package com.alvin.demo.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyFilter extends AuthorizationFilter {
    @Override
    protected boolean isAccessAllowed(
            ServletRequest servletRequest,
            ServletResponse servletResponse,
            Object mappedValue) throws Exception {
        //获取主题
        Subject subject = getSubject(servletRequest, servletResponse);
        String[] perms = (String[]) mappedValue;

        if(null == perms || perms.length == 0){
            return true;
        }
        for(String perm : perms){
            //只要有一个权限，就返回true
            if(subject.isPermitted(perm)){
//                System.out.println(perm);
                return true;
            }
        }
        return false;
    }
}
